package com.miplus.ccrm.core.service.crd;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.common.JSysUser;
import com.miplus.ccrm.common.JUsrPerm;
import com.miplus.ccrm.core.controller.vo.credit.CrdBillTailReqVo;
import com.miplus.ccrm.core.controller.vo.credit.CrdBillTailResVo;
import com.miplus.ccrm.core.pojo.CreditAccountEventDtl;
import com.miplus.ccrm.core.mapper.CreditAccountEventDtlMapper;
import com.miplus.ccrm.core.pojo.CreditAccountOutbill;
import com.miplus.ccrm.core.pojo.CreditCard;
import org.springframework.stereotype.Service;

/**
* @author pc
* @description 针对表【credit_account_event_dtl(信用卡已出/未出账单流水表T+1)】的数据库操作Service实现
* @createDate 2024-05-21 23:38:46
*/
@Service
public class CreditAccountEventDtlServiceImpl extends MPJBaseServiceImpl<CreditAccountEventDtlMapper, CreditAccountEventDtl>
    implements CreditAccountEventDtlService{

    @Override
    public IPage<CrdBillTailResVo> crdEventBillList(JSysUser user, CrdBillTailReqVo paras)
    {//240303的账单，是按交易时间统计240204-240303这个区间
        String $usrid=user.getUsrid();
        String cardstar= JUsrPerm.getPermission(user,JUsrPerm.DISSTAR_CARD);
        String billday1= "",billday2="";
        if(JPubUtils.IsNotEmpty(paras.getBillDay())&&paras.getBillDay().length()>=10) {
            billday1=JPubUtils.BilldayToStartday(paras.getBillDay().substring(0, 10));
            billday2 = paras.getBillDay();
        }
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                CrdBillTailResVo.class,
                new MPJLambdaWrapper<CreditAccountEventDtl>()
                        .selectAs(CreditAccountEventDtl::getBillAmtflag,CrdBillTailResVo::getDbCrInd)
                        .selectAs(String.format("fi_starSecu('%s','%s',t.card_nbr,'%s')",$usrid,JUsrPerm.DISSTAR_CARD,cardstar), CrdBillTailResVo::getCardNo)
                        .leftJoin(CreditCard.class,"cd",CreditCard::getCardNo,CreditAccountEventDtl::getCardNbr)
                        .selectAll(CreditAccountEventDtl.class)
                        .eq(CreditCard::getAcct,paras.getAcctNo())
                        .ge(JPubUtils.IsNotEmpty(billday1),CreditAccountEventDtl::getInpDate,JPubUtils.StrDateToInt(billday1))
                        .le(JPubUtils.IsNotEmpty(billday2),CreditAccountEventDtl::getInpDate,JPubUtils.StrDateToInt(billday2))
                        .orderByDesc(CreditAccountEventDtl::getInpDate,CreditAccountEventDtl::getInpTime)
        );
    }
}




